package com.acme.bankapp.domain.bank.account;

/**
 * 
 * @author nulls.narik
 *
 */
abstract class AbstractAccount implements Account {
	protected double balance;
	
	public AbstractAccount(double balance) throws Exception {
		this.balance = balance;
	}
	
	public double getBalance() {
		return balance;
	}
	
	public void deposit(double x) throws Exception {
		if (x < 0)
			throw new Exception("Add to balance less zero");
		balance += x;
	}
	
	public void withdraw(double x) throws Exception {
		if (x < 0)
			throw new Exception("Diff to balance less zero");
		
		if (balance < x) {
			throw new Exception("Balance less diff");
		}
		
		balance -= x;
	}
	
	public double maximumAmountToWithdraw() {
		return balance;
	}
}
